package com.ss.android.article.browser.preference;

import android.content.SharedPreferences;
import android.support.annotation.NonNull;

import com.ss.android.article.browser.c.d;
import com.ss.android.common.app.AbsApplication;

public class PreferenceManager {
    private static PreferenceManager instance;
    @NonNull
    public final SharedPreferences mSharedPreferences;
    private PreferenceManager() {
        this.mSharedPreferences = AbsApplication.getCtx().getSharedPreferences("browser_settings", 0);
    }

    public static PreferenceManager getInstance() {
        if (instance == null) {
            synchronized (PreferenceManager.class) {
                if (instance == null) {
                    instance = new PreferenceManager();
                }
            }
        }
        return instance;
    }

    public final void putInt(@NonNull String arg2, int arg3) {
        this.mSharedPreferences.edit().putInt(arg2, arg3).apply();
    }

    @NonNull
    public final Suggestion getSuggestion() {
        Suggestion suggestion;
        try {
            suggestion = Suggestion.valueOf(this.mSharedPreferences.getString("searchSuggestions", Suggestion.SUGGESTION_GOOGLE.name()));
        } catch (IllegalArgumentException argumentException) {
            suggestion = Suggestion.SUGGESTION_NONE;
        }
        return suggestion;
    }

    @NonNull
    public final String getDownloadLocation() {
        return this.mSharedPreferences.getString("downloadLocation", d.DEFAULT_DOWNLOAD_DIR);
    }

    public final int getSearch() {
        return this.mSharedPreferences.getInt("search", 0);
    }

    public final boolean getTextReflow() {
        return this.mSharedPreferences.getBoolean("textreflow", false);
    }

    public final int getTextSize() {
        return this.mSharedPreferences.getInt("textsize", 1);
    }

    public enum Suggestion {
        SUGGESTION_GOOGLE,
        SUGGESTION_DUCK,
        SUGGESTION_BAIDU,
        SUGGESTION_NONE
    }
}

